﻿using System.Collections.Generic;

namespace Com.OpenCode.Framework.Core
{
    public class Properties
    {
        private Dictionary<object, object> _Dictionary = new Dictionary<object, object>();

        #region IProperties 成员

        public Dictionary<object, object> Dictionary
        {
            get { return _Dictionary; }
        }

        public object Get(object key)
        {
            if (_Dictionary.ContainsKey(key))
            {
                return _Dictionary[key];
            }
            return "";
        }

        public void Add(object key, object value)
        {
            if (_Dictionary.ContainsKey(key))
            {
                _Dictionary[key] = value;
            }
            else
            {
                _Dictionary.Add(key, value);
            }
        }

        public bool Exist(string key)
        {
            return _Dictionary.ContainsKey(key);
        }

        public int Count
        {
            get { return _Dictionary.Count; }
        }

        public void Delete(object key)
        {
            if (_Dictionary.ContainsKey(key))
            {
                _Dictionary.Remove(key);
            }
        }

        public string GetString(object key)
        {
            return Get(key).ToString();
        }

        public int GetInt(object key)
        {
            int _Value = -1;
            int.TryParse(GetString(key), out _Value);
            return _Value;
        }

        public double GetDouble(object key)
        {
            double _Value = -1;
            double.TryParse(GetString(key), out _Value);
            return _Value;
        }

        public bool GetBool(object key)
        {
            bool _Value = false;
            bool.TryParse(GetString(key), out _Value);
            return _Value;
        }

        #endregion
    }
}